import logging

import pytest

from resource.pom.settings import Settings


class Test:
    app = Settings

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.点击设置应用')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        logging.info('预期结果1.进入设置界面')
        device.assert_current_window(self.app.window_name)

        logging.info('步骤2.点击隐私')
        device.click(*self.app.privacy_item)
        logging.info('预期结果2.进入隐私')
        device.refresh_layout()
        device.assert_text_exist('权限管理')

        logging.info('步骤3.点击权限管理，点击权限')
        device.click_element(device.get_element_by_text('权限管理'))
        device.refresh_layout()
        device.click_element(device.get_element_by_text('应用'))
        logging.info('预期结果3.进入权限管理-应用')
        device.refresh_layout()
        device.assert_type_exist('TextInput')
        device.assert_text_exist('备忘录')
        device.assert_text_exist('计算器')
        device.assert_text_exist('联系人')

        logging.info('步骤4.反复上下滑动应用列表，左右滑动或点击应用\权限切换')
        device.swipe(360, 640, 360, 300)
        device.swipe(360, 640, 360, 300)
        logging.info('预期结果4.可以上下左右滑动或点击权限/应用，无卡死、黑屏、白屏现象')
        device.refresh_layout()
        device.assert_text_exist('音乐')
        device.assert_text_exist('隐私')
        device.swipe(360, 640, 360, 900)
        device.swipe(360, 640, 360, 900)
        device.refresh_layout()
        device.assert_text_exist('备忘录')
        device.assert_text_exist('计算器')
        device.click_element(device.get_element_by_text('权限'))
        device.refresh_layout()
        device.assert_text_exist('位置信息')
        device.assert_text_exist('麦克风')
        device.click_element(device.get_element_by_text('应用'))

        logging.info('步骤5.点击进入应用列表中某一内容列，查看内容权限和封面权限数量')
        device.refresh_layout()
        note = device.get_element_by_text('备忘录')
        calculator = device.get_element_by_text('计算器')
        contacts = device.get_element_by_text('联系人')
        logging.info('预期结果5.应用实际权限数量和封面展示的权限数量一致')
        device.click_element(note)
        device.refresh_layout()
        device.assert_text_exist('多设备协同')
        device.assert_text_exist('图片和视频')
        device.go_back()
        device.click_element(calculator)
        device.refresh_layout()
        device.assert_text_exist('多设备协同')
        device.go_back()
        device.click_element(contacts)
        device.refresh_layout()
        device.assert_text_exist('暂无权限')
